package cn.songhaiqing.walle.help;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Locale;

import cn.songhaiqing.walle.bean.MyApp;

public class FormatHelper {
    public static final DecimalFormat df_0 = new DecimalFormat("0");
    public static final DecimalFormat df_00 = new DecimalFormat("00");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_HH = new SimpleDateFormat("HH");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_HH_mm = new SimpleDateFormat("HH:mm");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_HH_mm_ss = new SimpleDateFormat("HH:mm:ss");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_HHmm = new SimpleDateFormat("HHmm");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_MM_dd = new SimpleDateFormat("MM-dd");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_MMdd = new SimpleDateFormat("MM/dd");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_dd_MM_yyyy = new SimpleDateFormat("dd/MM/yyyy");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_yyyyMMdd = new SimpleDateFormat("yyyyMMdd");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_yyyyMMddHH = new SimpleDateFormat("yyyyMMddHH");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_yyyyMMddHHmm = new SimpleDateFormat("yyyyMMddHHmm");
    public static final SimpleDateFormat sdf_yyyy_MM = new SimpleDateFormat("yyyy-MM");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_yyyy_MM_dd = new SimpleDateFormat("yyyy-MM-dd");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_yyyy_MM_dd_HH = new SimpleDateFormat("yyyy-MM-dd HH");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_yyyy_MM_dd_HH_mm = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    @SuppressLint({"SimpleDateFormat"})
    public static final SimpleDateFormat sdf_yyyy_MM_dd_HH_mm_ss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static DecimalFormat df_0_0() {
        DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
        //  otherSymbols.setDecimalSeparator(FilenameUtils.EXTENSION_SEPARATOR);
        //   otherSymbols.setGroupingSeparator(FilenameUtils.EXTENSION_SEPARATOR);
        return new DecimalFormat("0.0", otherSymbols);
    }

    public static DecimalFormat df_0_00() {
        DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
        //  otherSymbols.setDecimalSeparator(FilenameUtils.EXTENSION_SEPARATOR);
        //  otherSymbols.setGroupingSeparator(FilenameUtils.EXTENSION_SEPARATOR);
        return new DecimalFormat("0.00", otherSymbols);
    }

    public static void changeFonts(ViewGroup root, Activity act) {
        Typeface tf = MyApp.getIntance().face;
        for (int i = 0; i < root.getChildCount(); i++) {
            View v = root.getChildAt(i);
            if (v instanceof TextView) {
                ((TextView) v).setTypeface(tf);
            } else if (v instanceof Button) {
                ((Button) v).setTypeface(tf);
            } else if (v instanceof EditText) {
                ((EditText) v).setTypeface(tf);
            } else if (v instanceof ViewGroup) {
                changeFonts((ViewGroup) v, act);
            }
        }
    }
}
